package com.clothing.service.impl;

import com.clothing.entity.BlackList;
import com.clothing.service.BlackListService;
import com.clothing.utils.Utils;
import com.clothing.utils.page.Filter;
import com.clothing.utils.page.Page;
import com.clothing.utils.page.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: BlackListService
 * @Description: Service
 * @author: Charles
 * @date: 2018/07/12 09:19
 * @version: 1.0
 */
@Service
public class BlackListServiceImpl extends BaseServiceImpl<BlackList, Long> implements BlackListService {

    @Override
    public BlackList findOne(Long userId) {
        List<Filter> filters = new ArrayList<>();
        filters.add(Filter.eq("user.id", userId));
        List<BlackList> blackLists = findList(null, filters, null);
        if (!Utils.isEmpty(blackLists)) {
            return blackLists.get(0);
        }
        return null;
    }

    @Override
    public Page<BlackList> findPage(String nickname, Pageable pageable) {
        List<Filter> filters = new ArrayList<>();
        if (!Utils.isEmpty(nickname)) {
            filters.add(Filter.like("user.nickname", "%" + nickname + "%"));
        }
        pageable.setFilters(filters);
        return findPage(pageable);
    }
}
